﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Kaca.Core.Common;
using Kunlun.Models;
using Kunlun.BusinessLogic;

namespace Kunlun.Controllers
{
    public class FrameController : Controller
    {

        /// <summary>
        /// 框画自定义
        /// </summary>
        /// <param name="pid">产品ID</param>
        /// <param name="aid">规格ID</param>
        public ActionResult Index()
        {
            string productID = RequestBase.GetString("pid");                            //框画产品ID
            int attid = RequestBase.GetInt("attid", 0);                                 //规则ID

            var productmodel = KunlunProduct.GetProductModel(productID);                //框画产品实体
            var attributemodel = KunlunProductAttribute.GetProductAttributes(attid);    //框画产品规则实体

            if (productmodel != null && attributemodel != null)
            {
                ViewBag.Attribute = attributemodel;

                //默认框条产品实体
                Product border = KunlunProduct.GetProductModel(WebLog.BorderID);
                ViewBag.Border = border;
                ViewBag.BorderUrl = WebLog.ImageHttp + border.Product_pic.FirstOrDefault().ImageUrl.Replace("\\", "/");

                //默认卡纸产品实体
                Product paper = KunlunProduct.GetProductModel(WebLog.PaperID);
                ViewBag.Paper = paper;
                ViewBag.PaperUrl = WebLog.ImageHttp + paper.ViewPic.Replace("\\", "/");

                return View(productmodel);
            }

            var err = new HandleErrorInfo(new Exception("参数错误!"), "Frame", "index");
            Response.StatusCode = 404;

            return View("Error", err);
        }

        /// <summary>
        /// 图片预览
        /// </summary>
        /// <param name="productpicUrl">产品图片地址</param>
        public PartialViewResult Photo(string productpicUrl)
        {
            ViewData["productpicUrl"] = productpicUrl;

            return PartialView("Photo");
        }

        /// <summary>
        /// 装裱信息
        /// </summary>
        /// <param name="attrinfo">产品的规格实体</param>
        public ActionResult MountInfo(Product_attributes attrinfo)
        {
            return PartialView(attrinfo);
        }

        /// <summary>
        /// 框画的框条选择
        /// </summary>
        /// <param name="CategoryID">框条的类别ID(默认91)</param>
        public ActionResult ChooseInfo(int CategoryID)
        {
            int frameCategoryID = CategoryID;        
            List<Category> cates = KunlunCategory.GetCategoryListByParentID(frameCategoryID);

            var TCates = new List<Category>();      
            foreach (Category c in cates)
            {
                TCates.AddRange(KunlunCategory.GetCategoryListByParentID(c.ID));
            }
            ViewData["Cates"] = cates;                                          //类别集合
            ViewData["Glass"] = KunlunProduct.GetProductByCategoryID("116");    //玻璃产品集合

            return PartialView(TCates);
        }

        //框条的图片列表
        public ActionResult FrameProduct(int? CategoryID)
        {
            CategoryID = CategoryID ?? 0;
            string cateID = CategoryID.Value.ToString();
            var model = new List<Product>();
            if (!string.IsNullOrEmpty(cateID))
            {
                model = KunlunProduct.GetProductByCategoryID(cateID);
            }

            return PartialView("FrameProduct", model);
        }

        /// <summary>
        /// 选择框画卡纸
        /// </summary>
        public PartialViewResult Kazhi()
        {
            string kazhiID = "92";
            var kazhiList = KunlunProduct.GetProductByCategoryID(kazhiID);

            return PartialView(kazhiList);
        }


    }
}
